const gameEnter = {
    rulerMsg: '#rulerMsg',
    pop_info: '.pop-info',
    pop_title: '.pop-title',
    pop_up_window: ".pop-up-window",
    common_window: '.common-window',
    ruler_btn: '.ruler-btn',
    game_ruler: '.game-ruler',
    p_close: '.close',
    g_close: '.g_close',
    pop_title: '.pop-title',
    pop_msg: '.pop-msg',
    check_get_prize: '', //保存是否获得奖品
    check_get_start: '', //保存是否参加过游戏
    startGame: '#startGame', //start button btn
    prizeEnter: '#prizeEnter', //enter prize btn
    bind_host: getServerHost() + 'bind.json',
    // bind_host:"http://10.122.202.211:8080/woAH-wap/poem/getUserInfo.action",
    finish_host: getServerHost() + 'finish.json',
    // finish_host:"http://10.122.202.211:8080/woAH-wap/poem/indexPage.action",
    joinData: {
        title: '您今天已参与过游戏啦！<br/>把机会让给还未参与过的小伙伴吧！',
        msg: `邀请好友扫描下方二维码`
    },
    focusData: {
        title: `为方便游戏后领取奖励<br/>请关注“江西联通”微信公众号`,
        msg: `长按下方二维码立即关注`
    },
    init: function() {
        this.getBind();
        this.closePop(this.p_close);
        this.closePop(this.g_close);
        this.rulerClick();
        this.startClick();
        this.prizeClick();

        // context.showPop(context.joinData);
    },
    //start and price
    startClick: function() {
        var context = this;
        $(context.startGame).click(function(e) {
            e.preventDefault();
            console.log(context.check_get_start);
            if ("true" == context.check_get_start) {
                layer_msg('您今日已参加过游戏，请明天再来')
            } else {
                location.href = './template/word_game.html';
            }
        })
    },
    prizeClick: function() {
        var context = this;
        $(context.prizeEnter).click(function(e) {
            e.preventDefault();
            if (context.check_get_prize) {
                layer_msg('您当前还未获得奖品')
            } else {
                location.href = './template/word_price.html';
            }
        })
    },
    // 获取绑定信息
    getBind: function() {
        var context = this;
        $.ajax({
            type: 'POST',
            url: context.bind_host,
            data: {
                "phone": '13277334751'
            },
            success: function(response) {
                response = response.data;
                if ('0000' == response.respcode) {
                    console.log(response);
                    //未绑定跳转到绑定页面
                    if ('0' == response.isBind) {
                        //跳转到绑定页面
                        layer_cofirm("您还未绑定手机号，点击跳转到绑定页面", 'http://www.baidu.com');
                        location.href = "";
                        return;
                    } else if ('0' == response.subcribe) {
                        // console.log(response.subcribe);
                        context.showPop(context.focusData)
                        return;
                    } else {
                        //验证是否参加过游戏
                        sessionStorage.setItem('phone', response.phone);
                        $.ajax({
                            type: 'POST',
                            url: context.finish_host,
                            data: {
                                "openid": 'openid'
                            },
                            success: function(response) {
                                response = response.data;
                                if ("0000" == response.respcode) {
                                    //接受是否参加过游戏
                                    context.check_get_start = response.is_add;
                                    //接收是否获得奖品
                                    context.check_get_prize = response.is_prized;
                                    if ("true" == response.is_add) {
                                        context.showPop(context.joinData);
                                    }
                                } else {
                                    layer_msg('请求参与接口失败')
                                }
                                console.log(response);
                            },
                            error: function(response) {}
                        })
                    }
                } else {
                    alert(response.message);
                }
                console.log(response);
            },
            error: function() {}
        })
    },
    // 显示弹窗
    showPop: function(data) {
        var context = this;
        $(context.pop_up_window).fadeIn();
        $(context.common_window).fadeIn();
        $(context.pop_info).html(data.msg);
        $(context.pop_title).html(data.title);
    },
    //绑定弹窗关闭按钮
    closePop: function(btn) {
        var context = this;
        var close_parent = $(btn).attr('data-parent')
        $(btn).click(function(e) {
            console.log(close_parent);
            e.preventDefault();
            $(close_parent).fadeOut(300)
        })
    },
    //点击活动规则
    rulerClick: function() {
        var context = this;
        $(context.ruler_btn).click(function(e) {
            e.preventDefault();
            $(context.game_ruler).fadeIn(300);
        });
    }
}
gameEnter.init();
